<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\admin\model\WithdrawalModel;
use app\admin\model\OrdersModel;

class Withdrawal extends Common
{
	/**
	*	会员提现列表
	*/
	public function index()
	{
		$data = $this->request->param();
		$WithdrawalModel = new WithdrawalModel();

		$list = $WithdrawalModel->getdrawals($data);

		$page = $list->render();
		$this->assign('page',$page);
		$this->assign('list',$list);

		$this->assign('u_name',isset($data['u_name']) ? $data['u_name'] : '');
		$this->assign('w_name',isset($data['w_name']) ? $data['w_name'] : '');
		$this->assign('w_tel',isset($data['w_tel']) ? $data['w_tel'] : '');
		$this->assign('w_account',isset($data['w_account']) ? $data['w_account'] : '');
		$this->assign('w_status',isset($data['w_status']) ? $data['w_status'] : '');
		return $this->fetch();
	}

	/**
	*	添加会员提现信息
	*/
	public function add()
	{
		$OrdersModel = new OrdersModel();
		$user = $OrdersModel->getUsers();
		$this->assign('user',$user);
		return $this->fetch();
	}

	/**
	*	添加会员提现信息提交
	*/
	public function addPost()
	{
		if($this->request->isPost()){
			$data = $this->request->param();
			$WithdrawalModel = new WithdrawalModel();
			$result = $this->validate($data, 'WithdrawalValidate');

	        if ($result !== true) {

	            $this->error($result);
	        }
			$list = $WithdrawalModel->addDrawal($data);
			if($list){
				$this->success('添加成功');
			}else{
				$this->error('添加失败');
			}
		}
	}

	/**
	*	修改会员提现信息
	*/
	public function edit()
	{
		$data = $this->request->param();
		if($data){
			$WithdrawalModel = new WithdrawalModel();
			$list = $WithdrawalModel->getOne($data['id']);
			$this->assign('list',$list);
		}
		return $this->fetch();
	}

	/**
	*	修改会员提现信息
	*/
	public function editPost()
	{
		$data = $this->request->param();
		if($data){
			$WithdrawalModel = new WithdrawalModel();
			$list = $WithdrawalModel->editDrawal($data['id'],$data);
			$this->success('修改成功');
			
		}
	}

	/**
	*	删除会员提现信息
	*/
	public function delete()
	{
		$data = $this->request->param();
		if($data){
			$WithdrawalModel = new WithdrawalModel();
			$list = $WithdrawalModel->deleteDrawal($data['id']);
			if($list){
				$this->success('删除成功',url('/admin/Withdrawal/index'));
			}else{
				$this->error('删除失败');
			}
			
		}
	}

}